use crate::api::admin::*;
use crate::api::guest::*;
use crate::boot::hook_server::Rule;

use actix_web::web;
use async_session::{MemoryStore, Session, SessionStore as _};

pub struct AppState {
   pub foo: String,
   pub store : MemoryStore,
}

pub fn router_config(config: &mut web::ServiceConfig) {
   config.service(web::resource("/").route(web::get().to(base::index)));
   config.service(
       web::scope("/api/admin")
           // 注册拦截器中间件
           .wrap(Rule)
           .service(
               web::scope("/sys")
                   .service(web::resource("/get_member_data.bu").route(web::get().to(sys::get_member_data))) // 获取用户的登录信息
                   .service(web::resource("/get_option_params.bu").route(web::get().to(sys::get_option_params)))// 获取选项配置
                   .service(web::resource("/edit_password.bu").route(web::post().to(sys::edit_password))),  // 修改密码
           ),
   );
   config.service(
       web::scope("/api/guest") 
       .app_data(web::Data::new(AppState {
        foo: "bar".to_string(),
        store : MemoryStore::new(),
    }))
           .service(
               web::scope("/user") 
                   .service(web::resource("/login.bu").route(web::post().to(user::login))) // 用户登录 
                   .service(web::resource("/logout.bu").route(web::post().to(user::logout))) // 注销登录  
           ).service(
            web::scope("/test_session")  
                .service(web::resource("/test1.bu").route(web::get().to(test_session::test1))) // 注销登录 
                .service(web::resource("/test2.bu").route(web::get().to(test_session::test2))) // 注销登录 
                .service(web::resource("/test3.bu").route(web::get().to(test_session::test3))) // 注销登录 
                .service(web::resource("/test4.bu").route(web::get().to(test_session::test4))) // 注销登录 
        )
           .service(
               web::scope("/base")
                   .service(web::resource("/sysconfig.bu").route(web::get().to(base::sysconfig))) // 获取系统配置参数 
           ),
   );
}